/**
 * 
 */
package fr.design.patterns.observer;

import java.util.ArrayList;

/**
 * @author fred
 * 
 */
public class Point implements IObserver {
	private int x;
	private int y;
	private ArrayList<IObservable> observateurs;

	/**
	 * @return the x
	 */
	public int getX() {
		return x;
	}

	/**
	 * @param x
	 *            the x to set
	 */
	public void setX(int x) {
		this.x = x;
	}

	/**
	 * @return the y
	 */
	public int getY() {
		return y;
	}

	/**
	 * @param y
	 *            the y to set
	 */
	public void setY(int y) {
		this.y = y;
	}

	public Point(int x, int y) {
		this.x = x;
		this.y = y;
		observateurs = new ArrayList<IObservable>();
	}

	@Override
	public void addObserver(IObservable observable) {
		if (observable != null)
			observateurs.add(observable);
		else
			System.out.println("Observateur inconnu");
	}

	@Override
	public void delObservable(IObservable observable) {
		if (observable != null)
			observateurs.remove(observable);
		else
			System.out.println("Observateur inconnu");
	}

	@Override
	public void notifier() {
		for (IObservable o : observateurs)
			o.actualiser(this);
	}

	public void deplace(int x, int y) {
		this.x += x;
		this.y += y;
		this.notifier();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Point [x=" + x + ", y=" + y + "]";
	}
}
